<?php


namespace app\admin\controller\v1;


use app\common\controller\BaseController;
use app\admin\model\Rule as RuleModel;
use app\common\validate\RuleAndRoleValidate;

class Rule extends BaseController
{
    /**
     * 获取菜单列表
     * @return \think\response\Json
     */
    public function index()
    {
//        $list = (new RuleModel())->getList();
        $list = (new RuleModel())->Mlist();
        return self::showResCode('获取成功',['list'=>$list]);
    }

    /**
     * 保存数据
     * @return \think\response\Json
     * @throws \app\lib\exception\BaseException
     */
    public function save()
    {
        //验证参数
        (new RuleAndRoleValidate())->goCheck('saveMenu');
        //保存操作
       (new RuleModel())->Mcreate();
        return self::showResCodeWithOutData('添加成功',200);
    }
    public function update()
    {
        //验证参数
        (new RuleAndRoleValidate())->goCheck('saveMenu');
        //保存操作
        $result = (new RuleModel())->updateRule();
       if($result)  return self::showResCodeWithOutData('修改成功',200);
    }
    /**
     * 删除菜单
     * @return \think\response\Json
     */
    public function delete()
    {
        $result = (new RuleModel())->deleteOneData();
        if($result){
            return self::showResCode('删除成功',['data'=>$result]);
        }else{
            return self::showResCodeWithOutData('删除失败');
        }
    }
}